home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d875.lha / Blanker / Source.lha / Source / Blankers / ClockD / fClock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-23  |  8.5 KB  |  312 lines

  1. /** DoRev Header ** Do not edit! **
  2. *
  3. * Name             :  fClock.c
  4. * Copyright        :  Free Software
  5. * Creation date    :  12-May-93
  6. * Translator       :  SAS/C 6.2
  7. * Compiler opts.   :  See Makefile
  8. *
  9. * Date       Rev  Author               Comment
  10. * ---------  ---  -------------------  ----------------------------------------
  11. * 12-May-93    0  Michael D. Bayne     Floating clock blanker module
  12. *
  13. *** DoRev End **/
  14.  
  15. #include <exec/types.h>
  16. #include <exec/memory.h>
  17. #include <dos/dos.h>
  18. #include <dos/datetime.h>
  19. #include <intuition/intuition.h>
  20. #include <intuition/screens.h>
  21. #include <intuition/gadgetclass.h>
  22. #include <libraries/gadtools.h>
  23. #include <libraries/asl.h>
  24. #include <graphics/text.h>
  25. #include <graphics/gfxmacros.h>
  26. #include <graphics/copper.h>
  27. #include <graphics/videocontrol.h>
  28. #include <hardware/custom.h>
  29.  
  30. #include <clib/exec_protos.h>
  31. #include <clib/intuition_protos.h>
  32. #include <clib/graphics_protos.h>
  33. #include <clib/dos_protos.h>
  34. #include <clib/diskfont_protos.h>
  35. #include <clib/gadtools_protos.h>
  36. #include <clib/utility_protos.h>
  37. #include <clib/asl_protos.h>
  38. #include <clib/alib_protos.h>
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43.  
  44. #include "Clock.h"
  45. #include "/defs.h"
  46.  
  47. extern    struct    Custom far custom;
  48.  
  49. struct cPrefObject {
  50.     UBYTE fName[64], Speed, Cycle, Secs, Military;
  51.     struct TextAttr Font;
  52. };
  53.  
  54. struct    cPrefObject    nP;
  55.  
  56. STATIC    const    UBYTE    VersTag[] = "$VER:Clock 1.1 (5.12.93)";
  57.         UBYTE    infoString[] = "Floating Clock Module";
  58.  
  59. void setClockPrefs( void )
  60. {
  61.     UBYTE fName[256];
  62.  
  63.     strcpy( fName, nP.fName );
  64.     strcat( fName, " " );
  65.     if( nP.Font.ta_Style & FSF_BOLD ) strcat( fName, "(B)" );
  66.     if( nP.Font.ta_Style & FSF_ITALIC ) strcat( fName, "(I)" );
  67.     if( nP.Font.ta_Style & FSF_UNDERLINED ) strcat( fName, "(U)" );
  68.  
  69.         GT_SetGadgetAttrs( ClockGadgets[GD_SPEED], ClockWnd, 0L, GTSL_Level, nP.Speed, 0L );
  70.     GT_SetGadgetAttrs( ClockGadgets[GD_FTXT], ClockWnd, 0L, GTTX_Text, fName, 0L );
  71.     GT_SetGadgetAttrs( ClockGadgets[GD_FSIZE], ClockWnd, 0L, GTNM_Number, nP.Font.ta_YSize, 0L );
  72.     GT_SetGadgetAttrs( ClockGadgets[GD_MIL], ClockWnd, 0L, GTCY_Active, nP.Military, 0L );
  73.     GT_SetGadgetAttrs( ClockGadgets[GD_CYCLE], ClockWnd, 0L, GTCY_Active, nP.Cycle, 0L );
  74.     GT_SetGadgetAttrs( ClockGadgets[GD_SECS], ClockWnd, 0L, GTCY_Active, nP.Secs, 0L );
  75. }
  76.  
  77. int OKClicked( void )
  78. {
  79.     return( QUIT );
  80. }
  81.  
  82. int CANCELClicked( void )
  83. {
  84.     return( CANCEL );
  85. }
  86.  
  87. int SPEEDClicked( void )
  88. {
  89.     nP.Speed = ClockMsg.Code;
  90.     return( OK );
  91. }
  92.  
  93. int MILClicked( void )
  94. {
  95.     nP.Military = ClockMsg.Code;
  96.     return( OK );
  97. }
  98.  
  99. int CYCLEClicked( void )
  100. {
  101.     nP.Cycle = ClockMsg.Code;
  102.     return( OK );
  103. }
  104.  
  105. int SECSClicked( void )
  106. {
  107.     nP.Secs = ClockMsg.Code;
  108.     return( OK );
  109. }
  110.  
  111. int FONTClicked( void )
  112. {
  113.     struct FontRequester *fReq;
  114.  
  115.     if( fReq = ( struct FontRequester * )AllocAslRequestTags( ASL_FontRequest, ASL_FontName, (ULONG)nP.fName,
  116.         ASL_FontHeight, nP.Font.ta_YSize, ASL_MaxHeight, 100, TAG_DONE )) {
  117.         if( AslRequestTags( fReq, ASLFO_Window, ClockWnd, ASLFO_SleepWindow, TRUE, ASLFO_TitleText,
  118.             (ULONG)"Please choose a font...", 0L )) {
  119.             strcpy( nP.fName, fReq->fo_Attr.ta_Name );
  120.             nP.Font.ta_YSize = fReq->fo_Attr.ta_YSize;
  121.         }
  122.         FreeAslRequest( fReq );
  123.     }
  124.     setClockPrefs();
  125.     return( OK );
  126. }
  127.  
  128. int ClockVanillaKey( void )
  129. {
  130.     switch( ClockMsg.Code ) {
  131.     case 'o':
  132.         return( QUIT );
  133.     case 'c':
  134.         return( QUIT );
  135.     case 'f':
  136.         return( FONTClicked());
  137.     case 's':
  138.         GT_SetGadgetAttrs( ClockGadgets[GD_SPEED], ClockWnd, 0L, GTSL_Level, ++(nP.Speed) > 50 ?
  139.             nP.Speed = 50 : nP.Speed, 0L );
  140.         return( OK );
  141.     case 'S':
  142.         GT_SetGadgetAttrs( ClockGadgets[GD_SPEED], ClockWnd, 0L, GTSL_Level, --(nP.Speed) < 1 ?
  143.             nP.Speed = 1 : nP.Speed, 0L );
  144.         return( OK );
  145.     default:
  146.         return( OK );
  147.     }
  148. }
  149.  
  150. void prefs( UBYTE *prefData )
  151. {
  152.     LONG    retval = OK;
  153.  
  154.     CopyMem(( struct cPrefObject * )prefData, &nP, sizeof( struct cPrefObject ));
  155.     nP.Font.ta_Name = nP.fName;
  156.     if( !SetupScreen() ) { if( !OpenClockWindow()) {
  157.         CloseDownScreen();
  158.         setClockPrefs();
  159.         while( 1 ) {
  160.             WaitPort( ClockWnd->UserPort );
  161.             retval = HandleClockIDCMP();
  162.             if( retval == QUIT ) {
  163.                 CopyMem( &nP, prefData, sizeof( struct cPrefObject ));
  164.                 break;
  165.             }
  166.             if( retval == CANCEL ) break;
  167.         }
  168.         CloseClockWindow();
  169.     } } else CloseDownScreen();
  170. }
  171.  
  172. void getTime( UBYTE *time, struct cPrefObject *nP )
  173. {
  174.     struct    DateTime dt;
  175.     ULONG    h,m,s;
  176.  
  177.     CopyMem( DateStamp( &dt.dat_Stamp ), &dt.dat_Stamp, sizeof( struct DateStamp ));
  178.     dt.dat_StrDay = 0L;
  179.     dt.dat_StrDate = 0L;
  180.     dt.dat_StrTime = time;
  181.  
  182.     if( !DateToStr( &dt )) strcpy( time, "Half past skin-thirty" );
  183.     else {
  184.         sscanf( time, "%d:%d:%d", &h, &m, &s );
  185.         if( nP->Secs ) sprintf( time, "%2d:%02d:%02d", nP->Military?h:(!h?12:(h%13)+(h/13)), m, s );
  186.         else sprintf( time, "%2d:%02d", nP->Military?h:(!h?12:(h%13)+(h/13)), m );
  187.         if( !nP->Military ) strcat( time, h>11?"pm":"am" );
  188.     }
  189. }
  190.  
  191. VOID newCopperList( LONG height, struct ViewPort *vp )
  192. {
  193.     #define NUMCOLORS 45
  194.  
  195.     struct    UCopList    *uCopList;
  196.     struct    TagItem    uCopTags[] = { { VTAG_USERCLIP_SET, 0L }, { VTAG_END_CM, 0L } };
  197.     register    USHORT    i, index = rand()%NUMCOLORS, spc;
  198.         UWORD    spectrum[] = {  0x0F00, 0x0E10, 0x0D20, 0x0C30, 0x0B40, 0x0A50, 0x0960, 0x0870, 0x0780, 0x0690,
  199.                 0x05A0, 0x04B0, 0x03C0, 0x02D0, 0x01E0, 0x00F0, 0x00E1, 0x00D2, 0x00C3, 0x00B4,
  200.                 0x00A5, 0x0096, 0x0087, 0x0078, 0x0069, 0x005A, 0x004B, 0x003C, 0x002D, 0x001E,
  201.                 0x000F, 0x010E, 0x020D, 0x030C, 0x040B, 0x050A, 0x0609, 0x0708, 0x0807, 0x0906,
  202.                 0x0A05, 0x0B04, 0x0C03, 0x0D02, 0x0E01 };
  203.     
  204.     if( uCopList = ( struct UCopList * )AllocMem( sizeof( struct UCopList ), MEMF_PUBLIC|MEMF_CLEAR )) {
  205.  
  206.         spc = height/NUMCOLORS;
  207.  
  208.         CINIT( uCopList, NUMCOLORS );
  209.  
  210.         for( i = 0; i<NUMCOLORS; ++i ) {
  211.             CWAIT( uCopList, i*spc, 0 );
  212.             CMOVE( uCopList, custom.color[1], spectrum[(i+index)%NUMCOLORS] );
  213.         }
  214.  
  215.         CEND( uCopList );
  216.  
  217.         Forbid();
  218.         vp->UCopIns = uCopList;
  219.         Permit();
  220.  
  221.         VideoControl( vp->ColorMap, uCopTags );
  222.  
  223.         RethinkDisplay();
  224.     }
  225. }
  226.  
  227. void blank( struct bMessage *Msg )
  228. {
  229.     struct    TextFont    *font;
  230.     struct    cPrefObject    *nP = ( struct cPrefObject * )Msg->prefData;
  231.     struct    Screen        *Scr;
  232.     UBYTE    vals[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4,
  233.         3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  234.     UBYTE    scrClock[128], c1 = 0, c2 = 14, c3 = 28;
  235.     ULONG    x, y, Wid, Hei, len, numc, base, count = 0;
  236.     LONG    dx = 1, dy = 1;
  237.  
  238.     srand( (ULONG)VBeamPos() );
  239.  
  240.     nP->Font.ta_Name = nP->fName;
  241.     font = OpenDiskFont( &( nP->Font ));
  242.     base = font->tf_Baseline;
  243.  
  244.     Scr = OpenScreenTags( 0l, SA_DisplayID, Msg->sMod, SA_Depth, 1, SA_Quiet, TRUE, SA_Overscan,
  245.         OSCAN_STANDARD, SA_Font, &( nP->Font ), TAG_DONE );
  246.  
  247.     Wid = Scr->Width;
  248.     Hei = Scr->Height;
  249.  
  250.     SetRGB4( &(Scr->ViewPort), 0, 0L, 0L, 0L );
  251.     switch( nP->Cycle ) {
  252.     case 0:
  253.         SetRGB4( &(Scr->ViewPort), 1, vals[c1], vals[c2], vals[c3] );
  254.         break;
  255.     case 1:
  256.         SetRGB4( &(Scr->ViewPort), 1, rand()%15 + 1, rand()%15 + 1, rand()%15 + 1 );
  257.         break;
  258.     case 2:
  259.         SetRGB4( &(Scr->ViewPort), 1, 15, 15, 15 );
  260.         break;
  261.     case 3:
  262.         newCopperList( Hei, &( Scr->ViewPort ));
  263.         break;
  264.     }
  265.  
  266.     getTime( scrClock, nP );
  267.     if( nP->Secs ) numc = 8;
  268.     else numc = 5;
  269.     if( !nP->Military ) numc += 2;
  270.     while(( len = TextLength( &(Scr->RastPort), scrClock, numc )) >= Wid ) numc--;
  271.  
  272.     x = rand()%( Wid - len - 1 ) + 1;
  273.     y = rand()%( Hei - nP->Font.ta_YSize - 1 ) + 1;
  274.  
  275.     SetAPen( &(Scr->RastPort), 1 );
  276.     Move( &(Scr->RastPort), x, y + base );
  277.     Text( &(Scr->RastPort), scrClock, numc );
  278.  
  279.     while(!( SetSignal( 0L, 0L )&SIGBREAKF_CTRL_C )) {
  280.         if( !nP->Cycle ) if( !(++count%10 )) SetRGB4( &(Scr->ViewPort), 1, vals[c1 = ++c1%42],
  281.             vals[c2 = ++c2%42], vals[c3 = ++c3%42] );
  282.         getTime( scrClock, nP );
  283.         Move( &(Scr->RastPort), x, y + base );
  284.         Text( &(Scr->RastPort), scrClock, numc );
  285.         if(!( count%(51-nP->Speed ))) {    
  286.             ScrollRaster( &(Scr->RastPort), dx, dy, x-1, y-1, x+len+1, y+nP->Font.ta_YSize+1 );
  287.             x -= dx; y -= dy;
  288.             if( x < 2 ) dx = -1;
  289.             else if( x > Wid-len-2 ) dx = 1;
  290.             if( y < 2 ) dy = -1;
  291.             else if( y > Hei-nP->Font.ta_YSize-2 ) dy = 1;
  292.         }
  293.     }
  294.     SetSignal( 0L, SIGBREAKF_CTRL_C );
  295.  
  296.     if( font ) CloseFont( font );
  297.     CloseScreen( Scr );
  298. }
  299.  
  300. void defaults( UBYTE *prefData )
  301. {
  302.     strcpy( (( struct cPrefObject * )prefData )->fName, "topaz.font" );
  303.     (( struct cPrefObject * )prefData )->Font.ta_Name = (( struct cPrefObject * )prefData )->fName;
  304.     (( struct cPrefObject * )prefData )->Font.ta_YSize = 11;
  305.     (( struct cPrefObject * )prefData )->Font.ta_Style = FS_NORMAL;
  306.     (( struct cPrefObject * )prefData )->Font.ta_Flags = FPB_ROMFONT;
  307.     (( struct cPrefObject * )prefData )->Speed = 10;
  308.     (( struct cPrefObject * )prefData )->Cycle = 0;
  309.     (( struct cPrefObject * )prefData )->Military = 0;
  310.     (( struct cPrefObject * )prefData )->Secs = 0;
  311. }
  312.